import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

// 导入 模块化 动态侧边栏
import departments from '@/router/module/departments'
import settings from '@/router/module/settings'
import employees from '@/router/module/employees'
import permissions from '@/router/module/permissions'
import salarys from '@/router/module/salarys'
import social_securitys from '@/router/module/social_securitys'
import attendances from '@/router/module/attendances'
import approvals from '@/router/module/approvals'

//
// import demo from '@/views/demo/index.vue'
// 创建动态路由,需要权限
const asynctRoutes = [

  // 按照顺序排列
  // 组织架构
  departments,
  // 角色管理
  settings,
  // 员工管理
  employees,
  // 权限管理
  permissions,
  // 工资
  salarys,
  // 社保
  social_securitys,
  // 考勤
  attendances,
  // 审批
  approvals
]

// 静态路由,不需要权限
export const constantRoutes = [
  {
    path: '/import',
    component: Layout,
    hidden: true, // 不显示到左侧菜单
    children: [{
      path: '',
      component: () => import('@/views/import')
    }]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true },
  {
    path: '/sync',
    component: () => import('@/views/sync/index.vue')
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  /*  利用...组合到一起组成路由表 */
  routes: [...constantRoutes, ...asynctRoutes]
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
